using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class pages_Search : PagedPage
{
    string mode = "";
    public override string RequestString
    {
        get
        {
            if (mode == "tour") return Request.QueryString.ToString();
            return "";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        p = Request["page"];
        totals = 0;
        currentPage = GetPageNumber(p);
        {
            mode = Request["mode"];
            if (mode != null)
            {
                switch (mode)
                {
                    case "tour": LoadTours(); break;
                    case "hotel": LoadHotels(); break;
                    case "restaurant": LoadRestaurants(); break;
                }
            }
        }
    }
    public void LoadTours()
    {
        try
        {
            //get location id
            int locationId = -1;
            try
            {
                if (!(Request["loc"] == "")) locationId = int.Parse(Request["loc"]);
            }
            catch (Exception ex) { }
            //get low price
            decimal lowPrice = 0;
            if(Request["l"]!=null)lowPrice= decimal.Parse(Request["l"]);
            //get high price
            decimal highPrice = 99999999;
            try
            {
                if ((Request["h"] != "") && (Request["h"]!="max"))
                    highPrice = decimal.Parse(Request["h"]);
            }
            catch (Exception ex) { }

            string keyword = "%";
            if (Request["s"] != null) keyword ="%" +Request["s"]+"%";
            TourDAO daoTour = new TourDAO();
            if (locationId > 0)
                rptTour.DataSource = daoTour.GetToursAdvByLoc(currentPage, pageSize, ref totals, keyword, lowPrice, highPrice, false, locationId, ServiceObject.Published);
            else rptTour.DataSource = daoTour.GetToursAdv(currentPage,pageSize,ref totals,keyword,lowPrice,highPrice,false,ServiceObject.Published);
        rptTour.DataBind();
        }
        catch (Exception ex)
        {
        }
    }
    public void LoadHotels()
    {
        int locationId = -1;
        try
        {
            if (!(Request["loc"] == "")) locationId = int.Parse(Request["loc"]);
        }
        catch (Exception ex) { }
        int rank = 0;
        if (!(Request["q"] == null)) rank = int.Parse(Request["q"]);
        string s = "%";
        if (!(Request["s"] == null)) s ="%"+ Request["s"]+"%";
        PlaceDAO daoPlace = new PlaceDAO();
        rptHotel.DataSource = daoPlace.GetPlacesExtWithRank(currentPage, pageSize,ref totals, 1, locationId, "%", rank, ServiceObject.Published);
        rptHotel.DataBind();
        
    }
    public void LoadRestaurants()
    {
        int locationId = -1;
        try
        {
            if (!(Request["loc"] == "")) locationId = int.Parse(Request["loc"]);
        }
        catch (Exception ex) { }
        string s = "%";
        if (!(Request["s"] == null)) s = "%" + Request["s"] + "%";
        PlaceDAO daoPlace = new PlaceDAO();
        rptRestaurant.DataSource=daoPlace.GetPlacesExtByLoc(currentPage,pageSize,ref totals,2,locationId,s,false,ServiceObject.Published);
        rptRestaurant.DataBind();
    }
}
